package com.mezz.bones.framework.mybatis.dynamic.provider;

import cn.hutool.core.util.StrUtil;
import com.mezz.bones.framework.mybatis.dynamic.domain.dto.DynamicDataSourceInfo;

import java.util.ArrayList;
import java.util.List;

public class DefaultDataSourceInfoProviderImpl implements DataSourceInfoProvider {
    @Override
    public List<DynamicDataSourceInfo> loadAllDataSourceInfo() {

        List<DynamicDataSourceInfo> list = new ArrayList<>();
        for (int i = 2; i <= 2; i++) {
            DynamicDataSourceInfo dataSourceInfo = new DynamicDataSourceInfo();
            dataSourceInfo.setDatasourceKey("db" + i);
            dataSourceInfo.setUrl(StrUtil.format("jdbc:mysql://127.0.0.1:3306/bones-{}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true"
                ,i
            ));
            dataSourceInfo.setUsername("root");
            dataSourceInfo.setPassword("123456");
            dataSourceInfo.setDriverClassName("com.mysql.cj.jdbc.Driver");
            list.add(dataSourceInfo);
        }

        return list;

    }

    @Override
    public DynamicDataSourceInfo loadDataSourceByKey(String dataSourceKey) {
        DynamicDataSourceInfo d3 = new DynamicDataSourceInfo();

        d3.setDatasourceKey("db3");
        d3.setUrl("jdbc:mysql://127.0.0.1:3306/bones-3?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true");
        d3.setUsername("root");
        d3.setPassword("123456");
        d3.setDriverClassName("com.mysql.cj.jdbc.Driver");
        return d3;
    }

}
